//
//  MainViewCell.m
//  IpadTestB
//
//  Created by edianzu on 2017/6/27.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "MainViewCell.h"

@implementation MainViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
    self.selectionStyle =UITableViewCellSelectionStyleNone;
    return self;
}

-(void) creatUI{
    self.contentView.backgroundColor =UIColorFromRGB(241, 244, 248);
    self.topLine = [[UIView alloc]init];
    self.topLine.backgroundColor = UIColorFromRGB(208, 63, 0);
    [self.contentView addSubview:self.topLine];
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(10*AutoScaleHorizontal);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.size.mas_equalTo(CGSizeMake(3*AutoScaleHorizontal, (65/2)*AutoScaleVertical));
    }];
    
    self.redCircle = [[UIImageView alloc]init];
    self.redCircle.image = [UIImage imageNamed:@"redCircle"];
    [self.contentView addSubview:self.redCircle];
    [self.redCircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.topLine.mas_centerX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.bottomLine = [[UIView alloc]init];
    self.bottomLine.backgroundColor = UIColorFromRGB(208, 63, 0);
    [self.contentView addSubview:self.bottomLine];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(10*AutoScaleHorizontal);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(3*AutoScaleHorizontal, (65/2)*AutoScaleVertical));
    }];
    
    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.font =[UIFont boldSystemFontOfSize:20*AutoScaleHorizontal];
    self.timeLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.redCircle.mas_right).with.offset(10*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.redCircle.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(130*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.rightBackView = [[UIView alloc]init];
    self.rightBackView.backgroundColor = [UIColor whiteColor];
    self.rightBackView.layer.cornerRadius = 10;
    [self.contentView addSubview:self.rightBackView];
    [self.rightBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.timeLabel.mas_right).with.offset(2*AutoScaleHorizontal);
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(5*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(650*AutoScaleHorizontal, 75*AutoScaleVertical));
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:20*AutoScaleHorizontal];
    [self.rightBackView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.rightBackView.mas_left).with.offset(35*AutoScaleHorizontal);
        make.top.mas_equalTo(self.rightBackView.mas_top).with.offset(15*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(430*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.numberLabel = [[UILabel alloc]init];
    self.numberLabel.textColor = [UIColor blackColor];
    self.numberLabel.font = [UIFont systemFontOfSize:18*AutoScaleHorizontal];
    [self.rightBackView addSubview:self.numberLabel];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.rightBackView.mas_left).with.offset(35*AutoScaleHorizontal);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(12*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(380*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.teacherLabel = [[UILabel alloc]init];
    self.teacherLabel.textColor = [UIColor blackColor];
    self.teacherLabel.font = [UIFont systemFontOfSize:18*AutoScaleHorizontal];
    [self.rightBackView addSubview:self.teacherLabel];
    [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).with.offset(20*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(135*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    
    self.arrowImg = [[UIImageView alloc]init];
    self.arrowImg.image = [UIImage imageNamed:@"arrowImage"];
    [self.rightBackView addSubview:self.arrowImg];
    [self.arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.teacherLabel.mas_right);
        make.centerY.mas_equalTo(self.teacherLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 15*AutoScaleVertical));
    }];
    
}

-(void)relayoutCellWithModel:(PlanModel *)model andIndex:(NSInteger)index andArrCount:(NSInteger)count andNumber:(NSNumber*)number{
    if (index == 0) {
        self.topLine.hidden =YES;
    }
    if (index == count-1) {
        self.bottomLine.hidden =YES;
    }
    NSString * timeStr = [model.CreateTime substringWithRange:NSMakeRange(0, 10)];
    self.timeLabel.text = timeStr;
    self.titleLabel.text = model.Title;
    self.numberLabel.text = [NSString stringWithFormat:@"%@人参加",number];
    self.teacherLabel.text = [NSString stringWithFormat:@"教师:%@",model.CreateTeacher];
}
@end
















